package com.wss.day06;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/4/26
 */


class Student {
    private String name;
    private String studentId;

    public Student(String name, String studentId) {
        this.name = name;
        this.studentId = studentId;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name) &&
                Objects.equals(studentId, student.studentId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, studentId);
    }

    @Override
    public String toString() {
        return "Student{" + "name='" + name + '\'' + ", studentId='" + studentId + '\'' + '}';
    }
}

class StudentSystem {
    private Set<Student> students = new HashSet<>();


    public boolean addStudent(Student student) {
        if (student == null) {
            System.out.println("错误：学生对象不能为null");
            return false;
        }
        return students.add(student);
    }

    public void displayAllStudents() {
        System.out.println("当前系统中的学生：");
        students.forEach(System.out::println);
    }
}

public class Main {
    public static void main(String[] args) {
        StudentSystem system = new StudentSystem();

        // 测试添加学生
        System.out.println("添加张三(001): " + system.addStudent(new Student("张三", "001")));
        System.out.println("添加李四(002): " + system.addStudent(new Student("李四", "002")));
        System.out.println("再次添加张三(001): " + system.addStudent(new Student("张三", "001")));

        system.displayAllStudents();
    }
}
